package com.fiveGroup.pojo.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class DataVo<T> {
    private int code;
    private String msg;
    private T data;

    // 快速创建有参成功响应
    public static <T> DataVo<T> success(T data) {
        return new DataVo<>(200, "success", data);
    }
    // 快速创建无参成功响应
    public static <T> DataVo<T> success() {
        DataVo<T> dataVo = new DataVo<>();
        dataVo.setCode(200);
        dataVo.setMsg("success");
        return dataVo;
    }
    // 快速创建失败响应
    public static <T> DataVo<T> fail(int code, String message) {
        return new DataVo<T>(code, message, null);
    }


    public static <T> DataVo<T> fail( String message) {
        DataVo<T> dataVo = new DataVo<>();
        dataVo.setCode(400);
        dataVo.setMsg(message);
        return dataVo;
    }


}
